package com.its.common.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author lx
 * @Date 2021/1/22 14:05
 * @Description
 */
public class VerifyFieldUtil {

    private static Pattern mobilePattern = Pattern.compile("^[1]\\d{10}$");

    private static Pattern carNoPattern = Pattern.compile("^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([A-Z0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$");

    private static Pattern numberPattern = Pattern.compile("^-?[0-9]+");

    private static Pattern stringNumberPattern = Pattern.compile("-?[0-9]*.?[0-9]*");

    /**
     *  正则：手机号（简单）, 1字头＋10位数字即可.
     * @param in
     * @return
     */
    public static boolean validateMobilePhone(String in) {
        return mobilePattern.matcher(in).matches();
    }

    /**
     * 车牌号验证
     * @param carNo
     * @return
     */
    public static boolean isCarNo(String carNo){
        Matcher m = carNoPattern.matcher(carNo);
        if (!m.matches()){
            return false;
        }
        return true;
    }
//
//    public static void main(String[] args) {
//        String s = "1.0";
//        System.out.println(stringIsNumber(s) + "");
//    }

    /**
     * 纯数字
     * @param str
     * @return
     */
    public static boolean isNum(String str){

        if(numberPattern.matcher(str).matches()){
            //数字
            return true;
        } else {
            //非数字
            return false;
        }
    }

    public static boolean stringIsNumber(String str){

        Matcher matcher = stringNumberPattern.matcher(str);
        boolean result = matcher.matches();
        if(result == true){
            return true;
        }else {
            return false;
        }
    }


}
